﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using VTR.Core;
using VTR.Title;
using VTR.Title.DataAccess;

namespace VTR.Title.Business
{
    public class Business : BaseClass       
    {
        // Public Properties
        public Title.DataAccess.Title Title { get; set; }

        public List<Title.DataAccess.Title> TitleList { get; private set; }

        public List<Title.DataAccess.TitleType> TitleTypeList { get; private set; }

        // Private Variables
        private Title.DataAccess.DataAccess db;

        // Constructor
        public Business(string userName)
            : base(userName)
        {
            db = new DataAccess.DataAccess();
        }

        public override bool isValid()
        {
            throw new NotImplementedException();
        }

        public override void Get()
        {
            throw new NotImplementedException();
        }

        public override void Get(int id)
        {
            this.Title = db.TitleGet(id);
        }

        public override void Insert()
        {
            try
            {
                // Add row metadata
                this.UpdateMetaData(true);

                // Insert row
                db.TitleSave(this.Title);
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public override void Update()
        {
            try
            {
                // Add row metadata
                this.UpdateMetaData();

                // Insert row
                db.TitleUpdate(this.Title);
            }
            catch (Exception)
            {

                throw;
            }
        }

        public override void Delete()
        {
            throw new NotImplementedException();
        }

        public override void Validate()
        {
            try
            {
                // Validate Title Application Date
                if (this.Title.ApplicationDate > DateTime.Now)
                {
                    // Do something
                }




            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public override void UpdateMetaData(bool newRow = false)
        {
            try
            {
                if (newRow)
                {
                    this.Title.CreatedBy = base.UserName;
                    this.Title.CreatedDate = DateTime.Now;
                }
                this.Title.UpdatedBy = base.UserName;
                this.Title.UpdatedDate = DateTime.Now;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void GetTitleTypes()
        {
            try
            {
                this.TitleTypeList = db.GetTitleTypes().ToList();
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
